﻿using System.IO;
using System.Net;
using System.Web.Mvc;

namespace easytodowebclient.Controllers
{
    public class NotesController : Controller
    {
        //
        // GET: /Notes/

        [HttpGet]
        public string Get()
        {
            string result = null;
            Stream stream = null;

            try
            {
                var request = WebRequest.Create("http://localhost:8159/Notes") as HttpWebRequest;
                //request.Accept = "application/xml";

                if (request.GetResponse().ContentLength > 0)
                {
                    stream = request.GetResponse().GetResponseStream();
                    
                    var streamReader = new StreamReader(stream);
                    
                    result = streamReader.ReadToEnd();
                }
            }
            finally
            {
                if(stream != null)
                    stream.Close();

                if (result == null)
                    result = string.Empty;
            }

            return result;
        }
    }
}
